package listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import dao.ConnectionFactory;

/**
 * Application Lifecycle Listener implementation class Contextlistener
 *
 */
@WebListener
public class Contextlistener implements ServletContextListener {

    /**
     * Default constructor. 
     */
    public Contextlistener() {
        // TODO Auto-generated constructor stub
    }

	/**
     * @see ServletContextListener#contextDestroyed(ServletContextEvent)
     */
    public void contextDestroyed(ServletContextEvent arg0)  { 
        
    }

	/**
     * @see ServletContextListener#contextInitialized(ServletContextEvent)
     */
    public void contextInitialized(ServletContextEvent arg0)  { 
        ServletContext sctxt = arg0.getServletContext();
        String dbName = sctxt.getInitParameter("dbName");
        String username = sctxt.getInitParameter("username");
        String password = sctxt.getInitParameter("pwd");
//        System.out.println(dbName);
//        System.out.println(username);
//        System.out.println(password);
        if(dbName!=null) {
        	ConnectionFactory.setDbName(dbName);
        }
        if(username!=null) {
        	ConnectionFactory.setUsername(username);
        }
        if(password!=null) {
        	ConnectionFactory.setPassword(password);
        }
    }
	
}
